home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
gsdbloo.exe
/
DEMOR001.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-29
|
4KB
|
133 lines
program DemoR001;
{------------------------------------------------------------------------------
DBase Relational File Maker
Useless Examples
Demo Program
Copyright (c) Richard F. Griffin
10 February 1992
102 Molded Stone Pl
Warner Robins, GA 31088
-------------------------------------------------------------
This unit creates the files that will be used to demonstrate
how to link the relationships between dBase files for data
retrieval based on common fields in two files.
This will first build a master file and then create a transaction
file using the UNIQUEID field in the master file as the key. The
transactions will insert the UNIQUEID field in each record as the
MASTERID field. This field will be used to link back to the master
record.
A Master file index on the UNIQUEID field will be created.
A Transaction file index on the MASTERID field will be created.
The Master file will have the structure defined in GS_GENF.PAS.
The Transaction file structure is:
MASTERID C 8 0 Uses UNIQUEID from Master Record
FULLNAME C 40 0 In Lastname~FirstName format
TRANDATE D 8 0
AMOUNT N 8 2
PAYTYPE C 1 0
-------------------------------------------------------------------------------}
uses
CRT,
GS_Strng,
GS_Date,
GS_dBase,
GS_dBFld,
GS_GenF,
GS_dB3Wk;
type
FldRecPtr = ^FldRecTyp;
FldRecTyp = array[1..GS_dBase_MaxRecField] of GS_dBase_Field;
var
MstrFile : GS_dBFld_Objt;
TranFile : GS_dBFld_Objt;
f : FldRecPtr;
t : string;
ix : integer;
rn : integer;
FLoc : integer;
tfRanNum : word;
tfFullName : string[40];
tfTranDate : longint;
tfAmount : real;
tfPayType : real;
tfPayTypeS : string[1];
procedure InsertField(s : string; t : char; l,d : integer);
begin
if FLoc >= GS_dBase_MaxRecField then exit;
inc(FLoc);
s := AllCaps(s);
CnvStrToAsc(s,f^[FLoc].FieldName,11);
f^[FLoc].FieldType := t;
f^[FLoc].FieldLen := l;
f^[FLoc].FieldDec := d;
f^[FLoc].FieldAddress := 0;
FillChar(f^[FLoc].Reserved,20,#0);
end;
Procedure MakeTranFile;
begin
New(f);
FLoc := 0;
InsertField('MASTERID','C',8,0);
InsertField('FULLNAME','C',40,0);
InsertField('TRANDATE','D',8,0);
InsertField('AMOUNT','N',8,2);
InsertField('PAYTYPE','C',1,0);
GS_dB3_Build('DEMOR1TF',f,FLoc);
end;
begin
ClrScr;
Writeln('Making DEMOR1MF.DBF Master File');
MakeTestData('DemoR1MF', 20, false);
WriteLn('DEMOR1MF Complete');
Writeln('Making DEMOR1TF.DBF Transaction File');
MakeTranFile;
WriteLn('DEMOR1TF Complete');
WriteLn('Creating Transactions');
MstrFile.Init('DEMOR1MF');
MstrFile.Open;
MstrFile.IndexTo('DEMOR1ID','UNIQUEID');
MstrFile.Index('DEMOR1ID');
TranFile.Init('DEMOR1TF');
TranFile.Open;
TranFile.IndexTo('DEMOR1TN','MASTERID');
TranFile.Index('DEMOR1TN');
Randomize;
for rn := 1 to 50 do
begin
ix := Random(20) + 1;
MstrFile.GetRec(ix);
tfFullName := MstrFile.StringGet('LASTNAME') + '~' +
MstrFile.StringGet('FIRSTNAME');
tfTranDate := GS_Date_Curr - Random(31);
tfAmount := (Random(30000) + 100);
tfAmount := tfAmount/100;
tfPayType := Random(4);
str(tfPayType:1:0,tfPayTypeS);
TranFile.Blank;
TranFile.FieldPut('MASTERID',MstrFile.FieldGet('UNIQUEID'));
TranFile.StringPut('FULLNAME',tfFullName);
TranFile.DatePut('TRANDATE',tfTranDate);
TranFile.NumberPut('AMOUNT',tfAmount);
TranFile.FieldPut('PAYTYPE',tfPayTypeS);
TranFile.Append;
end;
MstrFile.Close;
TranFile.Close;
end.